package com.gitee.wsl.mathematics.matrix.mat4

import com.gitee.wsl.mathematics.matrix.ext.setIdentity

class LazyMat4(val update: (MutableMat4) -> Unit) {
    private val mat = MutableMat4()

    var isDirty = true

    fun get(): Mat4 {
        if (isDirty) {
            update(mat)
            isDirty = false
        }
        return mat
    }

    fun clear() {
        isDirty = false
        mat.setIdentity()
    }
}


/**
 * A wrapper for [Mat4] that will invoke [update] when getting, if [isDirty].
 *
 * @param update the update function to invoke on the [Mat4], if dirty.
 * @author Colton Daily
 * @date 11/27/2021
 */
class LazyMat4f(val update: (MutableMat4f) -> Unit) {
    private val mat = MutableMat4f()

    var isDirty = true

    fun get(): Mat4f {
        if (isDirty) {
            update(mat)
            isDirty = false
        }
        return mat
    }

    fun clear() {
        isDirty = false
        mat.setIdentity()
    }
}